#include <iostream>
#include <vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

void binaryTreePathsHelper(TreeNode* root, vector<int>& path, vector<vector<int>>& res) {
    if (!root) {
        return;
    }
    path.push_back(root->val);
    if (!root->left && !root->right) {
        res.push_back(path);
    } else {
        binaryTreePathsHelper(root->left, path, res);
        binaryTreePathsHelper(root->right, path, res);
    }
    path.pop_back();
}

vector<vector<int>> binaryTreePaths(TreeNode* root) {
    vector<vector<int>> res;
    vector<int> path;
    binaryTreePathsHelper(root, path, res);
    return res;
}

int main() {
    TreeNode* root = new TreeNode(1);
    root->left = new TreeNode(2);
    root->right = new TreeNode(3);
    root->left->right = new TreeNode(5);

    vector<vector<int>> res = binaryTreePaths(root);

    for (int i = 0; i < res.size(); i++) {
        for (int j = 0; j < res[i].size(); j++) {
            cout << res[i][j] << "->";
        }
        cout << "NULL" << endl;
    }